package com.rgp.serviceprice.utils;

import com.rgp.internalcommon.utils.CalculatePriceUtils;
import com.rgp.serviceprice.pojo.TollRule;
import java.math.BigDecimal;

/**
 * @author nhp
 * @version 1.0
 * @description TODO
 * @date 2024-04-26 18:36
 */
public class TollRulePriceCalculateUtils {

    public static String calculatePrice(TollRule tollRule, String distance, String duration){
        Double startFare = tollRule.getStartFare();
        Double startMile = tollRule.getStartMile();
        Double unitPricePerMile = tollRule.getUnitPricePerMile();
        Double unitPricePerMinute = tollRule.getUnitPricePerMinute();
        String price = "0";
        //起步里程价
        price = CalculatePriceUtils.add(price, startFare.toString());
        //记程费用
        Double transferDistance = new Double(distance) / 1000;
        Double tollDistance = (transferDistance - startMile) < 0 ? 0 : transferDistance - startMile;
        price = CalculatePriceUtils.multiply(unitPricePerMile.toString(), tollDistance.toString(),price);
        //计时费用
        String transferDuration = CalculatePriceUtils.divide(duration, "60");
        price = CalculatePriceUtils.multiply(unitPricePerMinute.toString(),transferDuration,price);
        //返回总价
        return new BigDecimal(price).setScale(2,BigDecimal.ROUND_HALF_UP).toString();
    }
}
